package com.atguigu.chapter05.Transform;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/3/3 15:29
 */
public class Flink07_Connect {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> numDS = env.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<String> strDS = env.fromElements("a", "b", "c", "d");
        DataStreamSource<String> strDS1 = env.fromElements("a", "b", "c", "d");


        // TODO Transform - 合流 Connect
        ConnectedStreams<Integer, String> connect = numDS.connect(strDS);


        SingleOutputStreamOperator<Object> resultDS = connect.map(new CoMapFunction<Integer, String, Object>() {
            @Override
            public Object map1(Integer value) throws Exception {
                return null;
            }

            @Override
            public Object map2(String value) throws Exception {
                return null;
            }
        });

        // 如果 connect多条流： 先两条connect，调用算子处理，之后再跟 另外的流 connect
//        resultDS.connect()

        env.execute();
    }
}
/*
    Connect：
        1）connect 只能连接两条流
        2）两条流的数据类型可以不一样
        3）如果 connect多条流： 先两条connect，调用算子处理，之后再跟 另外的流 connect

 */